<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
$link=connect();

if($_SERVER['REQUEST_METHOD'] == 'POST') {
    $data = escape($link, $_POST);
    // 对密码进行md5加密
    $data['pw'] = md5($data['pw']);
    $query = "INSERT INTO member (username, pw, sex, phonenum, address, email) 
              VALUES ('{$data['username']}', '{$data['pw']}', '{$data['sex']}', 
                      '{$data['phonenum']}', '{$data['address']}', '{$data['email']}')";
    execute($link, $query);
    header("Location: simpleTable.php");
    exit;
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <link rel="stylesheet" href="../css/table.css">
</head>
<body>
    <h2 class="page-title">添加用户</h2>
    <div class="form-container">
        <form method="post">
            <div class="form-group">
                <label>用户名:</label>
                <input type="text" name="username" required>
            </div>
            <div class="form-group">
                <label>密码:</label>
                <input type="password" name="pw" required>
            </div>
            <div class="form-group">
                <label>性别:</label>
                <input type="text" name="sex">
            </div>
            <div class="form-group">
                <label>电话:</label>
                <input type="text" name="phonenum">
            </div>
            <div class="form-group">
                <label>地址:</label>
                <input type="text" name="address">
            </div>
            <div class="form-group">
                <label>邮箱:</label>
                <input type="email" name="email">
            </div>
            <div class="form-buttons">
                <button type="submit" class="add-btn">添加</button>
                <a href="simpleTable.php" class="edit-btn" style="margin-left:10px;">返回</a>
            </div>
        </form>
    </div>
</body>
</html>
